<?php

namespace App\Observers\Train;

use App\Models\Train\TrainSeat\TrainSeat;
use Illuminate\Support\Facades\Cache;
use function config;

class TrainSeatObserver
{
    /**
     * Handle the User "created" event.
     *
     * @param TrainSeat $seat
     *
     * @return void
     */
    public function created(TrainSeat $seat)
    {
        $cache_key = "Train:Seat:{$seat->train_code}:{$seat->from_code}:{$seat->to_code}:{$seat->seat_name}";
        Cache::put($cache_key, $seat->refresh(), 5 * config('trip.ttl.day'));
    }

    /**
     * Handle the User "updated" event.
     *
     * @param TrainSeat $seat
     *
     * @return void
     */
    public function updated(TrainSeat $seat)
    {
        $cache_key = "Train:Seat:{$seat->train_code}:{$seat->from_code}:{$seat->to_code}:{$seat->seat_name}";
        Cache::put($cache_key, $seat->refresh(), 5 * config('trip.ttl.day'));
    }

    public function saved(TrainSeat $seat)
    {
        $cache_key = "Train:Seat:{$seat->train_code}:{$seat->from_code}:{$seat->to_code}:{$seat->seat_name}";
        Cache::put($cache_key, $seat->refresh(), 5 * config('trip.ttl.day'));
    }
}
